{% extends "../../layui/layouts/main.html" %}

{% block mainbody %}
<div id="menu-index">

    <script type="text/html" id="tool">
        {% verbatim %}
        {{# if(d.status === 1){ }}
        <a class="layui-btn layui-btn-info layui-btn-xs" lay-event="checked">审核通过</a>
        {{#  } }}

            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="remove">删除</a>
        {% endverbatim %}
    </script>

    {% include "_search.tpl" %}

    <div class="layui-card">
        <div class="layui-card-header yak-card-header">
            {{Header}}
        </div>
        <div class="layui-card-body">
            <table id="drug-table" lay-filter="drug-table-filter"></table>
        </div>
    </div>

</div>
{% endblock %}

{% block script %}
<script>
    layui.use(['grid', 'layarea', 'laydate'], function () {
        var pager = layui.grid
            , layarea = layui.layarea
            , laydate = layui.laydate
            , tableId = "drug-table"
            , laytpl = layui.laytpl
            , tableFilter = "drug-table-filter"
            , searchFilter = "drug-search"
            , cols = [
                {width: 60, field: "_serial", title: "序号"},
                {field: "phone", title: "手机号"},
                {field: "username", title: "用户账号"},
                {field: "nickname", title: "用户昵称"},
                {field: "address", title: "所属地区"},
                {field: "company", title: "所属单位"},
                {field: "statusLabel", title: "状态"},
                {fixed: 'right', width: 150, align: 'center', toolbar: '#tool'}
            ]
            , table = {
                "id": tableId,
                "elem": "#" + tableId,
                "limit": 8,
                "limits": [10, 20, 50, 100],
                "cols": [cols],
                "method": "post",
                "request": {"pageName": "page", "limitName": "per-page"},
                "url": "/users",
                "toolbar": "#toolBar",
                "page": {"hash": "fenye"},
                "autoSort": false,
                "defaultToolbar": [{
                        "title": "导出Excel",
                        "layEvent": "OUTPUT_EXCEL",
                        "icon": "layui-icon-export"
                    }
                ]
            }
            , eventOptions = {
                "checked": {"url": "/user-checked"},
                "remove": {"url": "/user-del"},
                "OUTPUT_EXCEL": {"url": "/user-excel", "filename": "会员列表"}
            }
            , events = {
                "checked": function (obj, config, that) {
                    var $ax = layui.ax;
                    var ajax = new $ax(config.url, function (res) {
                        layer.msg(res.msg)
                        that.reloadTable(null, null, true);
                        layer.close(index)
                    });
                    ajax.setMethod('post');
                    ajax.setDataValue("id", obj.data['id']);
                    ajax.send();
                    return false
                },
                "remove": function (obj, config, that) {
                    var $ax = layui.ax;
                    var ajax = new $ax(config.url, function (res) {
                        layer.msg(res.msg)
                        that.reloadTable(null, null, true);
                        layer.close(index)
                    });
                    ajax.setMethod('post')
                    ajax.setDataValue("id", obj.data['id']);
                    ajax.send();
                    return false
                }
            }

        layarea.render({
            elem: '#'+ searchFilter,
            change: function (res) {
                //选择结果
                console.log(res)
            }
        });

        laydate.render({
            elem: '#yak_dt_s'
        });

        laydate.render({
            elem: '#yak_dt_e'
        });

        pager.render({
            "searchFilter": searchFilter,
            "tableId": tableId,
            "tableFilter": tableFilter,
            "sort": "server",
            "countCache": true,
            "table": table,
            "editor": {},
            "eventOptions": eventOptions
        }, events)

    })
</script>
{% endblock %}